const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

class Util {
  static randomString(len) {
    let str = '';
    for (let i = 0; i < len; i++) {
      str += CHARS.charAt(Math.floor(Math.random() * CHARS.length));
    }
    return str;
  }
  static uuid(prefix = 'D') {
    let uuid = [];
    uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
    uuid[14] = '4';
    let r;
    for (let i = 0; i < 36; i++) {
      if (!uuid[i]) {
        r = 0 | (Math.random() * 16);
        uuid[i] = CHARS[i == 19 ? (r & 0x3) | 0x8 : r];
      }
    }
    return (prefix ? prefix : '') + uuid.join('');
  }
}

export default Util;
